package com.slm.krstartimes.activity;

import android.app.Activity;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.Toast;

import com.slm.krstartimes.R;

/**
 * Created by lanou3g on 15/8/20.
 */
public class AboutusActivity extends Activity implements GestureDetector.OnGestureListener, View.OnTouchListener {
    private GestureDetector mGestureDetector;
    private int verticalMinDistance = 30;
    private int middleDistance = 150;
    private int minVelocity = 0;
    private RelativeLayout aboutuslayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.aboutus);
        aboutuslayout = (RelativeLayout) findViewById(R.id.aboutuslayout);
        mGestureDetector = new GestureDetector(this);
        aboutuslayout.setOnTouchListener(this);
        aboutuslayout.setLongClickable(true);

    }

    @Override
    public boolean onDown(MotionEvent motionEvent) {
        return false;
    }

    @Override
    public void onShowPress(MotionEvent motionEvent) {

    }

    @Override
    public boolean onSingleTapUp(MotionEvent motionEvent) {
        return false;
    }

    @Override
    public boolean onScroll(MotionEvent motionEvent, MotionEvent motionEvent1, float v, float v1) {
        return false;
    }

    @Override
    public void onLongPress(MotionEvent motionEvent) {

    }

    /**
     * 滑动返回
     *
     * @param e1
     * @param e2
     * @param v
     * @param v1
     * @return
     */
    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float v, float v1) {
        if (e2.getX() - e1.getX() > verticalMinDistance && Math.abs(v) > minVelocity && (Math.abs(e2.getY() - e1.getY()) < middleDistance)) {
            finish();
        } else if (e1.getX() - e2.getX() > verticalMinDistance && Math.abs(v) > minVelocity && (Math.abs(e2.getY() - e1.getY()) < middleDistance)) {
            Toast.makeText(AboutusActivity.this, "左滑", Toast.LENGTH_SHORT).show();
        }
        return false;
    }

    @Override
    public boolean onTouch(View view, MotionEvent motionEvent) {
        return mGestureDetector.onTouchEvent(motionEvent);
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        mGestureDetector.onTouchEvent(ev);
        // scroll.onTouchEvent(ev);
        return super.dispatchTouchEvent(ev);
    }
}
